package reit.ass3;

import java.util.concurrent.atomic.AtomicInteger;



/**
 * The Class RepairObject.
 */
class RepairObject extends Quantifiable implements RepairObjectInterface{

	/**
	 * Instantiates a new repair object.
	 */
	public RepairObject(){
		super("",0);
	}

	/**
	 * Instantiates a new repair object.
	 *
	 * @param r the r
	 */
	public RepairObject(final RepairObjectInterface r){
		super(r.getName(),r.getQuantity());
	}

	/**
	 * Instantiates a new repair object.
	 *
	 * @param name the name
	 * @param quantity the quantity
	 */
	public RepairObject(final String name, final int quantity) {
		super(name, quantity);
	}

	/* (non-Javadoc)
	 * @see ass3.RepairObjectInterface#reduceQuantityBy(ass3.RepairObjectInterface)
	 */
	@Override
	/**
	 * @pre r.getQunatity() <= this.getQuantity()
	 * @post this.getQunatity() == oldthis.getQunatity() - r.getQuantity()
	 * @throws RuntimeException trying to take more then there is 
	 * */
	public void reduceQuantityBy(final RepairObjectInterface r) {
		for(int i = r.getQuantity() ; i > 0 ; i--){
			if(this.getQuantity() > 0){
				this.setfQuantity(this.getfQuantity()-1);
			}
			else {
				throw new RuntimeException("Not Enough of RepairObject");
			}
		}
	}

	/* (non-Javadoc)
	 * @see ass3.RepairObjectInterface#increaseQuantityBy(ass3.RepairObjectInterface)
	 */
	@Override
	/**
	 * 
	 * @post this.getQunatity() == oldthis.getQunatity() + r.getQuantity()
	 * */
	public void increaseQuantityBy(final RepairObjectInterface r) {
		for(int i = r.getQuantity() ; i > 0 ; i--){
			if(this.getQuantity() >= 0){
				this.setfQuantity(this.getfQuantity()+1);
			}
			else 
				throw new RuntimeException("Quantity < 0");
		}

	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		StringBuilder s = new StringBuilder();
		s.append(this.getfQuantity());
		return s.toString();
	}



}
